package com.greateamd.timetableasy.server.services;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.greateamd.timetableasy.client.services.campus.CampusService;
import com.greateamd.timetableasy.domain.Campus;
import com.greateamd.timetableasy.domain.Event;
import com.greateamd.timetableasy.domain.exceptions.DBServerSideException;
import com.greateamd.timetableasy.server.dao.CampusDAO;

@Service("campusService")
public class CampusServiceImpl implements CampusService {

	private CampusDAO campusDAO;
	public void setCampusDAO(CampusDAO campusDAO) {
		this.campusDAO = campusDAO;
	}
	
	@Override
	public boolean save(Campus campus) throws DBServerSideException {
		try {
			campusDAO.save(campus);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
		return true;
	}

	@Override
	public Campus find(int id) throws DBServerSideException{
		try {
			return campusDAO.getById(id);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Campus> getAll() throws DBServerSideException {
		try {
			return campusDAO.getAll();
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean remove(Campus campus) throws DBServerSideException {
		try {
			campusDAO.delete(campus);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public boolean update(Campus campus) throws DBServerSideException {
		try {
			campusDAO.update(campus);
			return true;
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

	@Override
	public List<Event> getPlanning(Campus selectedCampus, Date fromDate,Date toDate) {
		try {
			return campusDAO.getPlanning(selectedCampus, fromDate, toDate);
		} catch (Exception e) {
			throw new DBServerSideException(e.getMessage());
		}
	}

}
